package com.okyai.kt.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.okyai.common.annotation.Log;
import com.okyai.common.enums.BusinessType;
import com.okyai.kt.domain.RecordAnnex;
import com.okyai.kt.service.IRecordAnnexService;
import com.okyai.common.core.controller.BaseController;
import com.okyai.common.core.domain.AjaxResult;
import com.okyai.common.utils.poi.ExcelUtil;
import com.okyai.common.core.page.TableDataInfo;

/**
 * 档案方案附件Controller
 * 
 * @author okyai
 * @date 2021-03-20
 */
@Controller
@RequestMapping("/kt/annex")
public class RecordAnnexController extends BaseController
{
    private String prefix = "kt/annex";

    @Autowired
    private IRecordAnnexService recordAnnexService;

    @RequiresPermissions("kt:annex:view")
    @GetMapping()
    public String annex()
    {
        return prefix + "/annex";
    }

    /**
     * 查询档案方案附件列表
     */
    @RequiresPermissions("kt:annex:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RecordAnnex recordAnnex)
    {
        startPage();
        List<RecordAnnex> list = recordAnnexService.selectRecordAnnexList(recordAnnex);
        return getDataTable(list);
    }

    /**
     * 导出档案方案附件列表
     */
    @RequiresPermissions("kt:annex:export")
    @Log(title = "档案方案附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RecordAnnex recordAnnex)
    {
        List<RecordAnnex> list = recordAnnexService.selectRecordAnnexList(recordAnnex);
        ExcelUtil<RecordAnnex> util = new ExcelUtil<RecordAnnex>(RecordAnnex.class);
        return util.exportExcel(list, "annex");
    }

    /**
     * 新增档案方案附件
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存档案方案附件
     */
    @RequiresPermissions("kt:annex:add")
    @Log(title = "档案方案附件", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RecordAnnex recordAnnex)
    {
        return toAjax(recordAnnexService.insertRecordAnnex(recordAnnex));
    }

    /**
     * 修改档案方案附件
     */
    @GetMapping("/edit/{annexId}")
    public String edit(@PathVariable("annexId") Long annexId, ModelMap mmap)
    {
        RecordAnnex recordAnnex = recordAnnexService.selectRecordAnnexById(annexId);
        mmap.put("recordAnnex", recordAnnex);
        return prefix + "/edit";
    }

    /**
     * 修改保存档案方案附件
     */
    @RequiresPermissions("kt:annex:edit")
    @Log(title = "档案方案附件", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RecordAnnex recordAnnex)
    {
        return toAjax(recordAnnexService.updateRecordAnnex(recordAnnex));
    }

    /**
     * 删除档案方案附件
     */
    @RequiresPermissions("kt:annex:remove")
    @Log(title = "档案方案附件", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(recordAnnexService.deleteRecordAnnexByIds(ids));
    }
}
